﻿@{ ViewBag.Title = "Index";
    Layout = "~/Areas/Shared/_LayuiList.cshtml"; }

<input style="display: none" name="tbid" id="tbid" value="@ViewBag.tbid">

<!--数据表格-->
<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>

<script src="~/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="~/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script>
    layui.use(["table", "form", "exLayer", "exUtils", "miniPage"], function () {
        let table = layui.table;
        let form = layui.form;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;
        let miniPage = layui.miniPage;

        let $ = layui.$;

        let ThisTable = table.render({
            elem: "#tableId",
            url: "/SysTable/TbSetUp/GetDbFieldist?tbid=" + $("#tbid").val(),
            defaultToolbar: ['exports'],
            toolbar: "#toolbarTpl",
            cols: [[
                { type: "numbers", title: "序号" },
                { field: "ColumnName", title: "列名", sort: true },
                { field: "DataType", title: "类型", sort: true },
                { field: "IndexName", title: "指标", sort: true }
            ]],
            done: function (res, curr, count) {
                console.log(res, curr, count);
            }
        });

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "add":
                    add();
                    break;
            }
        });

        function add() {
            exUtils.ajax("/SysTable/TbBasic/CreatTableDB", "post", { tbid: $("#tbid").val().trim() }, true).done(function (response) {
                ThisTable.reload({
                    where: { tbid: $("#tbid").val().trim() },
                    page: { curr: 1 }
                });
                return false;
            }).fail(function (error) {
                console.log(error);
            });
            return false;
        }

    })
</script>
<!-- 头工具栏模板-->
<script type="text/html" id="toolbarTpl">
    <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="add" id="add"><i class="fa fa-plus"></i>创建数据表</button>
</script>